<script setup>
import { ref } from 'vue'
import { resumeDeleteService } from '@/api/candidate'
import { Delete } from '@element-plus/icons-vue'
import { useCandidateStore } from '@/stores'
const loading = ref(false) //加载
/*获取*/
const candidateStore = useCandidateStore()
const getList = () => {
  loading.value = true
  candidateStore.getResumeList()
  loading.value = false
}

/*删除文件*/
const handleDelete = async (informationId) => {
  await ElMessageBox.confirm('你确认删除该文件吗？', '温馨提示', {
    type: 'warning',
    confirmButtonText: '确认',
    cancelButtonText: '取消'
  })
  loading.value = true
  await resumeDeleteService(informationId)
  getList()
  ElMessage({ type: 'success', message: '删除成功' })
  loading.value = false
}
</script>

<template>
  <layout-com title="简历管理">
    <template #extra>
      <el-button @click="getList" color="#354152" :dark="isDark"
        >刷新数据</el-button
      >
    </template>
    <!-- 主体部分 -->

    <el-table
      :data="candidateStore.resumeList"
      size="large"
      :stripe="true"
      v-loading="loading"
    >
      <el-table-column label="序号" width="150px">
        <template #default="scope">
          {{ scope.$index + 1 }}
        </template>
      </el-table-column>
      <el-table-column label="文件下载地址" width="400px">
        <template v-slot="scope">
          <!-- 将 informationFile 属性转换为链接 -->
          <a :href="scope.row.informationFile" target="_blank"
            ><span v-if="scope.row.informationFile">{{
              scope.row.informationFile.split('/').pop()
            }}</span></a
          >
        </template>
      </el-table-column>
      <el-table-column label="文件名" width="300px" prop="originalFilename" />
      <el-table-column label="操作" align="right">
        <template #default="scope">
          <el-button
            :icon="Delete"
            size="small"
            @click="handleDelete(scope.row.informationId)"
            >Delete</el-button
          >
        </template>
      </el-table-column>
      <template #empty>
        <el-empty description="如果您已上传文件请尝试刷新数据!!!" />
      </template>
    </el-table>
  </layout-com>
</template>

<style lang="scss" scoped>
.el-table {
  min-height: 580px;
  width: 100%;
}
</style>
